﻿using DragonBones;

using UnityEngine;

namespace Assets.XyzCode.Fight.Game.Enemy
{
    /// <summary>
    /// 敌人行为
    /// </summary>
    public partial class Enemy_X_Behav : MonoBehaviour
    {
        /** 视图, 也就是龙骨动画节点 */
        private GameObject _VIEW;

        /// <summary>
        /// Awake
        /// </summary>
        private void Awake()
        {
            _VIEW = transform.Find("VIEW").gameObject;
        }

        /// <summary>
        /// Start
        /// </summary>
        private void Start()
        {
            StartCoroutine(Think_XC());
        }

        /// <summary>
        /// Update
        /// </summary>
        private void Update()
        {
            // 更新当前状态
            UpdateCurrState();
        }

        /// <summary>
        /// LateUpdate
        /// </summary>
        private void LateUpdate()
        {
            if (null != _VIEW)
            {
                _VIEW.transform.rotation = Camera.main.transform.rotation;
            }
        }

        /// <summary>
        /// 播放龙骨 ( DragonBonez ) 动画
        /// </summary>
        /// <param name="animName">动画名称</param>
        /// <param name="playTimez">播放次数, -1 不限次数</param>
        /// <param name="timeScale">时间比例</param>
        private void PlayDBAnim(string animName, int playTimez = -1, float timeScale = 1)
        {
            if (null == _VIEW)
            {
                return;
            }

            // 获取龙骨动画组件
            UnityArmatureComponent dbComp = _VIEW.GetComponent<UnityArmatureComponent>();

            if (null != dbComp)
            {
                dbComp.animation.timeScale = timeScale;
                dbComp.animation.Play(animName, playTimez);
            }
        }
    }
}
